package com.jungle.bfi.controller;

import com.jungle.base.dao.SpecBuilder;
import com.jungle.base.domain.bo.BaseUserBo;
import com.jungle.base.domain.vo.JsonResult;
import com.jungle.bfi.domain.bo.VoucherTemplateBo;
import com.jungle.bfi.entity.VoucherTemplatePo;
import com.jungle.bfi.service.voucher.VoucherTemplateService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * [voucher]凭证模板实体类
 * @author jungle
 * @since 2025-02-18 09:59:41
 */
@Slf4j
@RestController
@RequestMapping("voucherTemplate")
public class VoucherTemplateController {
    @Resource
    private VoucherTemplateService voucherTemplateService;
    @PostMapping("store")
    public JsonResult<VoucherTemplatePo> store(@RequestBody VoucherTemplateBo qo) {
        VoucherTemplatePo po = voucherTemplateService.saveOrUpdate(qo, new BaseUserBo());
        return JsonResult.success(po);
    }

    @PostMapping("list")
    public JsonResult<List<VoucherTemplatePo>> list(@RequestBody VoucherTemplateBo bo) {
        List<VoucherTemplatePo> list = voucherTemplateService.findAll(new SpecBuilder<VoucherTemplatePo>(bo).toSpec());
        return JsonResult.success(list);
    }
}
